package com.example.springboot_admin.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_admin.pojo.Spec_options;
import com.example.springboot_admin.service.ISpec_optionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author svblack
 * @since 2024-09-17
 */
@RestController
@RequestMapping("/spec_options")
public class Spec_optionsController {
    @Autowired
    ISpec_optionsService spec_optionsService;

    @RequestMapping("list")
    IPage<Spec_options> list(@RequestParam(defaultValue = "1") int page,
                             @RequestParam(defaultValue = "5")int limit){
        return spec_optionsService.page(new Page<>(page,limit));
    }

    @RequestMapping("del")
    Integer del(int spec_optionsid){
        return spec_optionsService.removeById(spec_optionsid)?0:1;
    }

    @RequestMapping("doAdd")
    Integer doAdd(@RequestBody Spec_options spec_options){
        return spec_optionsService.save(spec_options)?0:1;
    }

    @RequestMapping("delMult")
    Integer delMult(@RequestBody List<Integer> ids){
        System.out.println("ids:"+ids);
        spec_optionsService.removeByIds(ids);
        return 0;
    }

    @RequestMapping("doEdit")
    Integer doEdit(@RequestBody Spec_options spec_options){
        UpdateWrapper<Spec_options> wrapper = new UpdateWrapper<>();
        if(spec_options.getValue()!=null&&!spec_options.getValue().isEmpty()){
            wrapper.set("value", spec_options.getValue());
        }
        wrapper.eq("spec_option_id", spec_options.getSpec_option_id());
        return spec_optionsService.update(wrapper)?0:1;
    }
}

